home *** CD-ROM | disk | FTP | other *** search
- program Project1;
-
- {$IFDEF WIN32}
- {$APPTYPE CONSOLE}
- {$ENDIF}
-
- uses
- {$IFDEF Windows}
- WinCrt,
- {$ENDIF}
- SysUtils,
- Classes,
- AALZHash in 'AALZHash.pas',
- AALZSWin in 'AALZSWin.PAS',
- AALZCmpr in 'AALZCmpr.pas',
- AABufStm in 'AABufStm.PAS';
-
- {$IFDEF Windows}
- function CompareMem(const Buf1, Buf2 : pointer; Count: Word): Boolean; assembler;
- asm
- PUSH DS
- LDS SI,Buf1
- LES DI,Buf2
- MOV CX,Count
- XOR AX,AX
- CLD
- REPE CMPSB
- JNE @@1
- INC AX
- @@1: POP DS
- end;
- {$ENDIF}
-
- function CompareStreams(aStream1, aStream2 : TStream) : boolean;
- var
- Buf1, Buf2 : PByteArray;
- BytesRead : integer;
- begin
- Result := false;
- if (aStream1.Size <> aStream2.Size) then
- Exit;
- aStream1.Position := 0;
- aStream2.Position := 0;
-
- GetMem(Buf1, 8192);
- try
- GetMem(Buf2, 8192);
- try
- BytesRead := aStream1.Read(Buf1^, 8192);
- aStream2.Read(Buf2^, 8192);
- if not CompareMem(Buf1, Buf2, BytesRead) then
- Exit;
- finally
- FreeMem(Buf2, 8192);
- end;
- finally
- FreeMem(Buf1, 8192);
- end;
- Result := true;
- end;
-
- procedure PackUnpack(const aFileName : string);
- var
- InStrm : TFileStream;
- OutStrm : TFileStream;
- InBufStm, OutBufStm : TaaBufferedStream;
- Equal : boolean;
- OrigSize : longint;
- Ratio : double;
- begin
- write('Processing ', aFileName);
-
- InStrm := TFileStream.Create(aFileName, fmOpenRead OR fmShareDenyNone);
- try
- OutStrm := TFileStream.Create('c:\LLL.LZA', fmCreate OR fmOpenReadWrite);
- try
- InBufStm := TaaBufferedStream.Create(InStrm, 8192);
- try
- OutBufStm := TaaBufferedStream.Create(OutStrm, 8192);
- try
- OrigSize := InStrm.Size;
- AALZCompress(InBufStm, OutBufStm);
- finally
- OutBufStm.Free;
- end;
- finally
- InBufStm.Free;
- end;
- finally
- OutStrm.Free
- end;
- finally
- InStrm.Free
- end;
-
- InStrm := TFileStream.Create('c:\LLL.LZA', fmOpenRead);
- try
- OutStrm := TFileStream.Create('c:\LLL.OUT', fmCreate OR fmOpenReadWrite);
- try
- InBufStm := TaaBufferedStream.Create(InStrm, 8192);
- try
- OutBufStm := TaaBufferedStream.Create(OutStrm, 8192);
- try
- if OrigSize = 0 then
- Ratio := -1
- else
- Ratio := (InStrm.Size * 100.0) / OrigSize;
- AALZDecompress(InBufStm, OutBufStm);
- finally
- OutBufStm.Free;
- end;
- finally
- InBufStm.Free;
- end;
- finally
- OutStrm.Free
- end;
- finally
- InStrm.Free
- end;
-
- InStrm := TFileStream.Create(aFileName, fmOpenRead OR fmShareDenyNone);
- try
- OutStrm := TFileStream.Create('c:\LLL.OUT', fmOpenRead);
- try
- Equal := CompareStreams(InStrm, OutStrm);
- finally
- OutStrm.Free
- end;
- finally
- InStrm.Free
- end;
-
- if Equal then
- writeln(' Passed ', Ratio:5:1, '%')
- else begin
- writeln(' Failed');
- readln;
- end;
-
- end;
-
- var
- Dir : string;
- SR : TSearchRec;
- Res : integer;
- begin
- if (ParamCount = 1) then
- Dir := ParamStr(1)
- else
- Dir := ExtractFilePath(ParamStr(0));
- if (Dir[length(Dir)] <> '\') then
- Dir := Dir + '\';
- Res := FindFirst(Dir + '*.*', faAnyfile, SR);
- while Res = 0 do begin
- if ((SR.Attr and faDirectory) = 0) then
- PackUnpack(Dir + SR.Name);
- Res := FindNext(SR);
- end;
- FindClose(SR);
-
- writeln('All done');
- readln;
- end.
-